import { getToken, setToken, removeToken } from '@/utils/storage'
import { getUserInfo } from '@/api/user'
const user = {

  namespaced: true,
  state: {
    // 读取登陆的tokin
    token: getToken(),
    userInfo: {}
  },
  getters: {
  },
  mutations: {
    // 存储登陆的tokin
    setToken(state, payload) {
      state.token = payload
      setToken(payload)
    },

    setuserInfo(state, payload) {
      state.userInfo = payload
    },

    removeToken(state) {
      state.token = {}
      removeToken()
    }
  },
  actions: {
    async Actions_getUserInfo(context) {
      try {
        // const res = await getUserInfo()
        // console.log(res)
        // this.setuserInfo(res.data)

        const res = await getUserInfo()
        // console.log(res)
        context.commit('setuserInfo', res.data)
      } catch {
        // 提示   获取用户信息失败
        this.toast('获取用户信息失败')
      }
    }
  }
}
export default user
